#pragma once
#ifndef __EPOLL_HPP__
#define __EPOLL_HPP__

#include <sys/epoll.h>
#include <vector>
#include <stdio.h>

class Epoll{
public:
    Epoll(size_t events_size):
        m_events(events_size)
    {
        m_epfd = epoll_create(1);
        if (m_epfd == -1)
            printf("epoll create error\n");
    }

    int epoll_add(EPOLL_EVENTS events, int fd, epoll_data_t data){
        epoll_event event;
        event.data = data;
        event.events = events;
        return epoll_ctl(m_epfd, EPOLL_CTL_ADD, fd, &event);
    }

    int epoll_del(int fd){
        return epoll_ctl(m_epfd, EPOLL_CTL_DEL, fd, nullptr);
    }

    int epoll_wait(int timeout){
        return ::epoll_wait(m_epfd, m_events.data(), m_events.size(), timeout);
    }

    epoll_event operator[](int ind){
        return m_events[ind];
    }
private:
    std::vector<epoll_event> m_events;
    int m_epfd;
};

#endif // __EPOLL_HPP__